﻿using System;
using System.Web.Security;
using System.Web.Profile;

namespace GameSchool.Models.AccountModels
{
    /// <summary>
    /// Þetta extension var fengið af: http://stackoverflow.com/questions/426609/how-to-assign-profile-values
    /// </summary>
    public class AccountProfile : ProfileBase
    {
        public static AccountProfile CurrentUser
        {
            get
            {
                var membershipUser = Membership.GetUser();
                return (AccountProfile)
                       (ProfileBase.Create(membershipUser.UserName));
            }
        }

        public string FullName
        {
            get { return ((string)(base["FullName"])); }
            set { base["FullName"] = value; Save(); }
        }

        public string SSN
        {
            get { return ((string)(base["SSN"])); }
            set { base["SSN"] = value; Save(); }
        }

        public AccountProperties.Gender Gender
        {
            get { return ((AccountProperties.Gender)(base["Gender"])); }
            set { base["Gender"] = value; Save(); }
        }

        public string Street
        {
            get { return ((string)(base["Street"])); }
            set { base["Street"] = value; Save(); }
        }

        public int PostalCode
        {
            get { return ((int)(base["PostalCode"])); }
            set { base["PostalCode"] = value; Save(); }
        }

        public string Country
        {
            get { return ((string)(base["Country"])); }
            set { base["Country"] = value; Save(); }
        }

        public string PhoneNumber
        {
            get { return ((string)(base["PhoneNumber"])); }
            set { base["PhoneNumber"] = value; Save(); }
        }

        public int DepartmentDegreeId
        {
            get { return ((int)(base["DepartmentDegreeId"])); }
            set { base["DepartmentDegreeId"] = value; Save(); }
        }

        public static AccountProfile GetProfileByUserName(string userName)
        {
            var membershipUser = Membership.GetUser(userName);
            return (AccountProfile)
                   (ProfileBase.Create(membershipUser.UserName));
        }

        public static AccountProfile GetProfileByUserId(Guid userId)
        {
            var membershipUser = Membership.GetUser(userId) ;
            return (AccountProfile)
                   (ProfileBase.Create(membershipUser.UserName));
        }
    }
}